package com.jason.canvaslayer.view;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.util.AttributeSet;
import android.view.View;

/**
 * @DESC:  canvas 层次图的构建使用
 * @Author: Jason
 * @Date: 16/9/26
 * @Time: 11:47
 */

public class LayerView1 extends View {

    private Paint mPaint;

    private int mViewWidth, mViewHeight;


    public LayerView1(Context context, AttributeSet attrs) {
        super(context, attrs);

        mPaint = new Paint(Paint.ANTI_ALIAS_FLAG);

    }

    @Override
    protected void onSizeChanged(int w, int h, int oldw, int oldh) {

        mViewHeight = h;
        mViewWidth = w;

    }

    @Override
    protected void onDraw(Canvas canvas) {
        // 绘制一个红色矩形
        mPaint.setColor(Color.RED);
        canvas.drawRect(mViewWidth / 2F - 200, mViewHeight / 2F - 200,
                mViewWidth / 2F + 200, mViewHeight / 2F + 200, mPaint);

        // 保存画布并绘制一个蓝色的矩形
        canvas.save();
        mPaint.setColor(Color.BLUE);
        canvas.drawRect(mViewWidth / 2F - 100, mViewHeight / 2F - 100,
                mViewWidth / 2F + 100, mViewHeight / 2F + 100, mPaint);
        canvas.restore();

    }
}
